package robocup.component.actions;

import robocup.component.math.RCMath;

/**
 * A TurnAction is used to change the players body-orientation by a certain
 * angle. Note that the defined angle only correspond to the turn-angle in case
 * of no speed of the agent. This is the effect of the simulated inertia.
 */
public class TurnAction
    extends Action {

  /**
   * The turn-angle of the command (-180,180]
   */
  private double _angle;

  /**
   * Constrcutor - an action to turn the agent
   * 
   * @param angle
   *          the angle to turn (-180,180] (note that the effective turnangle
   *          depends on the agents current speed).
   */
  public TurnAction(
      final double angle) {

    this._angle = RCMath.round(angle, Action.PARAMETER_PRECISION);
    this._type = TYPE.TURN;
  }

  /**
   * Returns the actions string representation:
   * 
   * @return (turn &lt;angle&gt;)<br>
   *         <br>
   */
  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();
    buf.append("(turn ");
    buf.append(this._angle);
    buf.append(")");
    return buf.toString();
  }

  /**
   * An action is worth sending if it effects the world.
   * 
   * @return true, if the angle is not equal to zero.
   */
  @Override
  public boolean isWorthSending() {

    return !(this._angle == 0);
  }

  /**
   * @return Returns the angle.
   */
  public double getAngle() {

    return this._angle;
  }

  /**
   * Sets a new angle to the command.
   * 
   * @param angle -
   *          the new angle.
   */
  public void setAngle(final double angle) {

    this._angle = angle;
  }
}
